#This will combine reads from multiple igv files. Then I want to normalize it to one of the ctrls with the most TA sites hit

import sys

#need to make dictionary of TA site and reads

TAsites = {}
for line in open(sys.argv[1]):
	split = line.split('\t')
	TAsites[int(split[1])]=[]

#print TAsites

for arg in sys.argv[1:]:
	for line in open(arg):
		split = line.split('\t')
		site = int(split[1])
		reads = int(split[3].rstrip())
		if site in TAsites:
			TAsites[site].append(reads)

#print TAsites

#Next add together read numbers and output as original igv
allreads = {}
for k,v in TAsites.iteritems():
	sumreads = sum(v)
	allreads[k]=sumreads
#print allreads

for line in open(sys.argv[1]):
	split = line.split('\t')
	#print len(split)
	site = int(split[1])
	if site in allreads:
		if len(split)<5:
			print "%s\t%d\t%d\t%d" % (split[0],site,int(split[2]),allreads[site])
		elif len(split)<6:
			print "%s\t%d\t%d\t%d\t%s" % (split[0],site,int(split[2]),allreads[site],split[4].rstrip())





